﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SiGeSIB
{
    public partial class UManageDefaultToolStrip : UserControl
    {
		public event EventHandler ExitClicked;
        public event EventHandler<EventArgs<string>> SearchTextChanged;
        public event EventHandler AddClicked;
        public event EventHandler EditClicked;
        public event EventHandler RemoveClicked;
		public event EventHandler ReloadClicked;

        public UManageDefaultToolStrip()
        {
            InitializeComponent();
			_FieldsToLock = new List<object>() 
			{
				tsbExit,
				tsbEdit,
				tsbAdd, 
				tsbRemove, 
				tstbSearch, 
				tsbReload 
			};
		}

		#region Attributes
		private List<object> _FieldsToLock;
		#endregion

		#region Properties
		public bool IsAddButtonVisible
		{
			get { return tsbAdd.Visible; }
			set { tsbAdd.Visible = toolStripSeparator2.Visible = value; }
		}
		#endregion

		public List<object> FieldsToLock { get { return _FieldsToLock; } }

		#region Event Handlers
		private void tsbAdd_Click(object sender, EventArgs e)
		{
			if (AddClicked != null)
				AddClicked(sender, e);
		}

		private void tsbEdit_Click(object sender, EventArgs e)
		{
			if (EditClicked != null)
				EditClicked(sender, e);
		}

		private void tsbRemove_Click(object sender, EventArgs e)
		{
			if (RemoveClicked != null)
				RemoveClicked(sender, e);
		}

		private void tstbSearch_TextChanged(object sender, EventArgs e)
		{
			if (SearchTextChanged != null)
				SearchTextChanged(sender, new EventArgs<string>(tstbSearch.Text));
		}

		private void tsbExit_Click(object sender, EventArgs e)
		{
			if (ExitClicked != null)
				ExitClicked(sender, e);
		}

		private void tsbReload_Click(object sender, EventArgs e)
		{
			if (ReloadClicked != null)
				ReloadClicked(sender, e);
		} 
		#endregion

		internal void RefreshUIState(DataRow row, bool isLocked)
		{
			tsbRemove.Enabled = 
				tsbEdit.Enabled = !isLocked && row != null;
		}
	}
}
